* Table 6: IMPACT HETEROGENEITY

use "${output}panel_r0_r1_r2.dta", clear // Load merged analysis panel

********************************************************************************

* Keep households surveyed in each round
keep if sample_household == 1

********************************************************************************

* Analyses

local model_1 "i.treatment##i.surveyround"
local model_2 "i.treatment##i.chirag_strata##i.surveyround"
local estimation_options ", absorb(hh_id) vce(cluster uniquegrp) nocons"

// Generate the fuel-collection time outcome variable
ren total_fuel_collection_time tot_fuel_coll_time
egen mean_fuel_coll = mean(tot_fuel_coll_time), by(surveyround)
replace tot_fuel_coll_time = mean_fuel_coll if mi(tot_fuel_coll_time)

// For total fuel-collection time
estimates clear
foreach var of varlist tot_fuel_coll_time {

	sum `var' if surveyround == 0 & treatment == 0 & chirag_strata == 0
	local `var'_m = `r(mean)'
	qui autofmt, input(``var'_m') dec(2) strict
	local `var'_m = `r(output1)'

	forval i = 1/2 {

		// Estimation
		reghdfe `var' `model_`i'' `estimation_options'
		estimates store `var'_`i'

		// Test of difference between two triple-diff. estimands
		capture noisily test 1.treatment#1.chirag_strata#1.surveyround = 1.treatment#1.chirag_strata#2.surveyround

	}
}

// For total fuelwood used weight
bys hh_id : egen fuel_weight_count = count(fuelwood_used_weight)

foreach var of varlist fuelwood_used_weight {

	sum `var' if surveyround == 0 & treatment == 0 & chirag_strata == 0 & fuel_weight_count > 1
	local `var'_m = `r(mean)'
	qui autofmt, input(``var'_m') dec(2) strict
	local `var'_m = `r(output1)'

	forval i = 1/2 {

			// Estimation
			reghdfe `var' `model_`i'' if fuel_weight_count > 1 `estimation_options'
			estimates store `var'_`i'

			// Test of difference between two triple-diff. estimands
			capture noisily test 1.treatment#1.chirag_strata#1.surveyround = 1.treatment#1.chirag_strata#2.surveyround

		}

}

********************************************************************************

// Generate table

estout fuelwood_used_weight_1 fuelwood_used_weight_2 tot_fuel_coll_time_1 tot_fuel_coll_time_2 ///
	using "${results}/table_impact_heterogeneity.tex", replace style(tex) ///
	cells("b(fmt(a2) star)" se(par fmt(a2))) ///
	keep(1.surveyround 2.surveyround ///
		1.treatment#1.surveyround 1.treatment#2.surveyround ///
		1.chirag_strata#1.surveyround 1.chirag_strata#2.surveyround ///
		1.treatment#1.chirag_strata#1.surveyround 1.treatment#1.chirag_strata#2.surveyround) ///
	stats(N r2_a, fmt(%15.0gc a2) labels("\(N\)" "Adjusted \(R^2\)")) ///
  	starlevels(* 0.10 ** 0.05 *** 0.01) ///
    collabels(none) mlabel(none) ///
	varlabels(1.surveyround "\({POST}_1\)" ///
			2.surveyround "\({POST}_2\)" ///
			1.treatment#1.surveyround "\({TREATMENT}_j \times {POST}_1\)" ///
			1.treatment#2.surveyround "\({TREATMENT}_j \times {POST}_2\)" ///
			1.chirag_strata#1.surveyround "\({NGO}_j \times {POST}_1\)" ///
			1.chirag_strata#2.surveyround "\({NGO}_j \times {POST}_2\)" ///
			1.treatment#1.chirag_strata#1.surveyround "\({TREATMENT}_j \times {NGO}_j \times {POST}_1\)" ///
			1.treatment#1.chirag_strata#2.surveyround "\({TREATMENT}_j \times {NGO}_j \times {POST}_2\)" ///
				, elist(1.surveyround " \addlinespace" ///
						2.surveyround " \addlinespace" ///
						1.treatment#1.surveyround " \addlinespace" ///
						1.treatment#2.surveyround " \addlinespace" ///
						1.chirag_strata#1.surveyround " \addlinespace" ///
						1.chirag_strata#2.surveyround " \addlinespace" ///
						1.treatment#1.chirag_strata#1.surveyround " \addlinespace") ///
				) ///
	prehead(  ///
		"\begin{table}" ///
		"\centering" ///
		"\caption{Impact of promotion on fuel collection and use in matched NGO/non-NGO villages}" ///
		"\begin{adjustbox}{max width=\textwidth}" ///
		"\label{t:impacts}" ///
		"\begin{threeparttable}" ///
		"\begin{tabular}{lcccc}" ///
		"\toprule" ///
		"& (1) & (2) & (3) & (4) \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5}" ///
        "& \multicolumn{2}{c}{Fuelwood use} & \multicolumn{2}{c}{Fuel-collection time} \\" ///
        "& \multicolumn{2}{c}{(kilograms per day)} & \multicolumn{2}{c}{(minutes per day)} \\" ///
        "\midrule" ///
		)  ///
	prefoot("\midrule" ///
		"Baseline non-NGO control mean & `fuelwood_used_weight_m' & `fuelwood_used_weight_m' & `tot_fuel_coll_time_m' & `tot_fuel_coll_time_m' \\" ///
		"Household fixed-effects & Yes & Yes & Yes & Yes \\" ///
		)  ///
	postfoot("\bottomrule" ///
		"\end{tabular}" ///
		"\begin{tablenotes}" ///
		"{\setlength\labelsep{0pt}" ///
		"\footnotesize" ///
		"\item \textit{Notes}. The outcome variables are daily fuelwood use (columns 1--2) and total time spent collecting fuels (columns 3--4) as measured during baseline, and midline and endline follow-up surveys (conducted approximately three and fifteen months after the start of the intervention, respectively). Daily fuelwood use is derived from a 24-hour before--after household-level fuel-weighing test; we restrict the analysis in columns (1) and (2) to the subsample of households that participated in such tests in at least two of our three survey rounds \( (N = 388) \). The outcome variable for fuel-collection time is derived from self-reported data on time spent (per day, week, or month) collecting fuelwood, crop residue, leaves, dung, biomass pellets, kerosene, LPG, biogas, and---if relevant---any other fuel used by the household; missing observations for time spent collecting fuel for up to six households in each survey round are replaced with the survey-round-specific sample mean value. The even-numbered columns present the results of estimating the triple-differences specification outlined in Equation \eqref{e:triple-diff}. The accompanying odd-numbered columns present results from estimating a double-differences specification without NGO-specific interactions for comparison. Standard errors (in parentheses) are clustered at the hamlet level. \sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\).}" ///
		"\end{tablenotes}" ///
		"\end{threeparttable}" ///
		"\end{adjustbox}" ///
		"\end{table}" ///
		)
